package cate.common.table.item.spice.sheet;

import cate.common.table.ESheet;
import cate.common.table.item.spice.row.SpiceCallRewardRow;
import cate.common.util.random.RWList;
import easy.java.dev.note.NoteClass;

import java.util.HashMap;
import java.util.Map;

@NoteClass(value = "占星概率")
public class SpiceCallRewardSheet extends ESheet<SpiceCallRewardRow> {

    @Override
    public String getSheetName() {
        return "占星概率";
    }

    private Map<Integer, RWList<SpiceCallRewardRow>> groupMap;

    @Override
    protected void onLoaded() {
        groupMap = new HashMap<>();
        for (SpiceCallRewardRow row : this.list) {
            RWList<SpiceCallRewardRow> rwList = groupMap.get(row.groupId);
            if (rwList == null) {
                rwList = new RWList<>();
                groupMap.put(row.groupId, rwList);
            }
            rwList.add(row);
        }
        groupMap.values().forEach(RWList::setup);
    }

    public SpiceCallRewardRow randomReward(int groupId) {
        RWList<SpiceCallRewardRow> rwList = groupMap.get(groupId);
        if (rwList == null) {
            return null;
        }
        return rwList.get();
    }
}
